package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.domain.Message;
import cn.wolfcode.trip.base.service.IMessageService;
import cn.wolfcode.trip.base.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("messages")
public class MessageController {
    @Autowired
    private IMessageService messageService;

    /**
     * 获取消息数据
     * @param userId
     * @return
     */
    @GetMapping
    public Map query(Long userId){
        Map map = messageService.query(userId);
        return map;
    }

    /**
     * 修改未查看消息的状态
     * @param userId
     * @param sendUserId
     * @return
     */
    @PutMapping
    public Object setNoReadMsg(Long userId,Long sendUserId){
        messageService.setNoReadMsg(userId,sendUserId);
        return new JsonResult();
    }

    /**
     * 获取消息内容
     * @param userId
     * @param sendUserId
     * @return
     */
    @GetMapping("/contents")
    public List<Message> getMessageContent(Long userId, Long sendUserId){
        List<Message> messages = messageService.getMessageContent(userId,sendUserId);
        return messages;
    }

    /**
     * 创建一条聊天内容
     * @param message
     * @return
     */
    @PostMapping
    public Object save(Message message){
        messageService.save(message);
        return new JsonResult();
    }
}
